// pages/myFollowing/myFollowing.js
const API = require('../../common/constant');
const util = require('../../utils/util');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pageIndex: 1,
    pageCount: 0,
    followerList: []
  },

  /**
   * 获取关注列表
   */
  getfollowerList: function(){
    let that = this;
    wx.showLoading({
      title: '正在加载',
    })
    util.http({
      url: API.URL.USER.FIND_FANINFO_BYPAGE ,
      data: {
        pageIndex: this.data.pageIndex,
        pageSize: 8,
      },
      success: (res) => {
        console.log('我关注的是：', res.data);
        wx.hideLoading();
        that.setData({
          followerList: this.data.followerList.concat(res.data.bussData),
          pageCount: res.data.pageCount
        });
        console.log(this.data.followerList);
      },
      fail: (res) => {
        console.log(res);
        console.log("!11111111111111111")
      }
    })
  },
  /**
   * 关注
   */
  following: function(e){
    console.log(e.target.id);
    util.http({
      url: API.URL.USER.ADD_ATTENTIONINFO,
      data: {
        id:e.target.id
      },
      success: res => {
        console.log(res);
        this.setData({
          followerList:[]
        })
        this.getfollowerList();
      },
      fail: err => {
        console.log(err);
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {
    this.getfollowerList();
    app.globalData.isNewFollowers = false;
  },
  onShow: function () {
    if(app.globalData.isNewFollowers) {
      this.setData({
        pageIndex: 1,
        pageCount: 0,
        followerList: []
      })
      this.getfollowerList();
      app.globalData.isNewFollowers = false;
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.pageCount <= this.data.pageIndex) return
    this.setData({
      pageIndex: this.data.pageIndex + 1
    })
    this.getfollowerList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})